import logging

import jsonpath
from exception.jsonpath_exception import JsonExpressScriptExtractException



def get_jsonpath_value(json_data,json_express_script):
    # logging.info(f"jsonpath提取的数据:{json_data}")
    # logging.info(f"jsonpath提取的数据类型:{type(json_data)}")
    # logging.info(f"jsonpath提取的json表达式:{json_express_script}")
    try:
        value = jsonpath.jsonpath(json_data, f"{json_express_script}")[0]
    except:
        logging.error(f"jsonpath提取出现异常")
        raise JsonExpressScriptExtractException(f"jsonpath提取出现异常")
    else:
        return value

def get_response_status_code_value(json_data):
    try:
        value = jsonpath.jsonpath(json_data, f"$..response_status_code")[0]
    except:
        logging.error(f"jsonpath提取出现异常")
        raise JsonExpressScriptExtractException(f"jsonpath提取出现异常")
    else:
        return value